<template>
	<app-layout>
		<view class="" v-if="list.length > 0">
			<xyz-masonry @itemClick="itemClick" :value="list" @click="del" :isdel="true" />
		</view>
		<view class="nopt" v-else>
			暂无关注
		</view>
	</app-layout>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import xyzMasonry from '../components/xyz-masonry.vue';
	let mallurl = null
	export default {
		data() {
			return {
				page: 1,
				limit: 20,
				pagecount: 1,
				list: [],
				mall_id: 1
			}
		},
		components: {
			xyzMasonry
		},
		computed: {
			...mapState({
				userInfo: state => state.user.info,
				storemall: state => state.malid.apimaUrl
			}),
		},
		onLoad(options) {
			this.mall_id = options.mall_id || 1
			mallurl = this.$siteInfo.apiroot + '?_mall_id=' + this.mall_id + '&r='
			this.getVideoList()
		},
		onReachBottom() {
			if (this.pagecount > this.page) {
				this.page++
				this.getVideoList()
			}
		},
		methods: {
			getVideoList() {
				this.$showLoading();
				this.$request({
					url: mallurl + this.$apiUrl.sixty.list,
					data: {
						page: this.page,
						page_size: this.limit,
						user_id: this.userInfo.options.user_id
					}
				}).then((res) => {
					// console.log(res);
					this.$hideLoading();
					uni.stopPullDownRefresh()
					this.pagecount = res.data.pagination.page_count

					this.list = this.list.concat(res.data.list);
				}).catch(err => {
					this.$hideLoading();
					uni.stopPullDownRefresh()
					// console.log(err);
				})
			},
			del(id) {
				this.$request({
					url: mallurl + this.$apiUrl.sixty.delete,
					method: 'post',
					data: {
						id: id,
						user_id: this.userInfo.options.user_id
					},
				}).then(res => {
					if (res.code == 0) {
						this.list = []
						this.pagecount = 1
						this.page = 1
						this.getVideoList()
					}
				}).catch(err => {
					console.log(err);
				})
			},
			itemClick(id) {
				uni.navigateTo({
					url: `/plugins/sixty/fullscreen/index?id=${id}&userid=${this.userInfo.options.user_id}&mall_id=${this.mall_id}`
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.nopt {
		text-align: center;
		line-height: 476rpx;
		font-size: 36rpx;
	}
</style>
